package com.seanzx.resolver.impl;

import com.seanzx.common.Lists;
import com.seanzx.common.Result;
import com.seanzx.constant.SymbolTable;
import com.seanzx.lexical.Token;
import com.seanzx.resolver.IResolver;
import com.seanzx.dp.ProcessorController;

import java.util.List;

public class ShowDatabaseResolver implements IResolver<Object> {
    ProcessorController processorController = ProcessorController.get();
    @Override
    public boolean matches(List<Token> tokens) {
        return tokens.size() == 2 &&
                tokens.get(0).getValue().equals(SymbolTable.SHOW) &&
                tokens.get(1).getValue().equals("DATABASES");
    }

    @Override
    public Object translate(List<Token> tokens) {
        return null;
    }

    @Override
    public boolean validate(Object parameter) {
        return true;
    }

    @Override
    public Result access(Object parameter) {
        Result<List<String>> result = processorController.showDatabase();
        if (result.isSuccess()) {
            return Result.ok(Lists.of(Lists.of("DATABASES"), result.getData()));
        }
        return result;
    }
}
